<?php
 
class Form extends CI_Controller {
 
    public function index()
    {
        $this->load->helper(array('form', 'url'));
 
        $this->load->library('form_validation');
 
        $this->form_validation->set_rules('username', 'Nom d utilisateur', 'callback_username_check');
        $this->form_validation->set_rules('password', 'Mot de passe', 'required');
        $this->form_validation->set_rules('passconf', 'Confirmation', 'required');
        $this->form_validation->set_rules('email', 'Email', 'required|is_unique[users.email]');
 
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('main/myform');
        }
        else
        {
            $this->load->view('formsuccess');
        }
    }
 
    public function username_check($str)
    {
        if ($str == 'test')
        {
            $this->form_validation->set_message('username_check', 'Le champ %s ne peut pas être égal à "test"');
        }
    }
}